<template>
  <van-field
      readonly
      required
      :name="name"
      :value='value'
      :label="label"
      :label-width="label_width"  />
</template>

<script>
import {queryByType} from "@/api/dictapi";
import { Notify } from 'vant'
export default {
  name: 'HelloWorld',
  data() {
    return {
      label_width:'',
      v_model:this.model,
      value:"",
      qType:""
    }
  },
  watch: {
  }, 
  props: {
    name:String,
    model:String,
    label:String,
    keyType:String
  },
  created(){
    let length = 0;
    for (let i = 0; i < this.label.length; i++) {
      const charCode = this.label.charCodeAt(i);
      if (charCode >= 0 && charCode <= 127) {
        length += 0.75;
      } else {
        length += 1;
      }
    }
    if(length >= 11) length=11;
    this.label_width=length+'em'
    if (!this.keyType){
      this.qType=this.name
    }else {
      this.qType=this.keyType
    }
    queryByType({ dictType:this.qType} )
      .then((result) => {
        if (!result.data) {
          Notify(result.message);
          return;
        }
        for(var i=0;i<result.data.data.length;i++){
          if(result.data.data[i].value==this.model){
            this.value = result.data.data[i].name;
          }
        }
      })
  }
}
</script>